home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / drivers / modetest.c < prev    next >
Text File  |  1993-12-06  |  6KB  |  230 lines

  1. /**
  2.  ** MODETEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include <grx.h>
  25. #include <mousex.h>
  26. #include <grdriver.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <ctype.h>
  30. #include <dos.h>
  31.  
  32. #ifdef __TURBOC__
  33. #define ENV_VAR "GRXDRV"
  34. #endif
  35.  
  36. #ifdef __GNUC__
  37. #define ENV_VAR "GO32"
  38. #endif
  39.  
  40. GR_DRIVER_MODE_ENTRY far *ttab,*gtab;
  41. int txt_modes,gra_modes;
  42. int vdr_driver = 0;
  43. int unsup = 0xff;
  44.  
  45. void list_modes(void)
  46. {
  47.     char buf[20];
  48.     char tentry[100];
  49.     char gentry[100];
  50.     char *env = getenv(ENV_VAR);
  51.     int  mode,setup;
  52.  
  53.     if(env != NULL)
  54.         printf("Value of environment variable \"%s\" is:\n\"%s\"\n\n",ENV_VAR,env);
  55.     printf("%-35s%s\n\n","Available text modes:","Available graphics modes:");
  56.     txt_modes = 0;
  57.     gra_modes = 0;
  58.     while((ttab[txt_modes].width != 0) || (gtab[gra_modes].width != 0)) {
  59.         tentry[0] = '\0';
  60.         gentry[0] = '\0';
  61.         if(ttab[txt_modes].width != 0) {
  62.         if(vdr_driver) {
  63.             mode  = ttab[txt_modes].mode.vdr.BIOS_mode;
  64.             setup = ttab[txt_modes].mode.vdr.custom_setup_index;
  65.         }
  66.         else {
  67.             mode  = ttab[txt_modes].mode.grn.BIOS_mode;
  68.             setup = ttab[txt_modes].mode.grn.custom_setup_index;
  69.         }
  70.         sprintf(tentry,
  71.             "(t%d%s  %3dx%-2d C:%-2d %s",
  72.             txt_modes+1,
  73.             ((txt_modes < 9) ? ") " : ")"),
  74.             ttab[txt_modes].width,
  75.             ttab[txt_modes].height,
  76.             ttab[txt_modes].number_of_colors,
  77.             (mode == unsup) ?
  78.             "Disabled" :
  79.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  80.         );
  81.         if((mode != unsup) && (setup != 0)) {
  82.             sprintf(buf," *%d*",setup);
  83.             strcat(tentry,buf);
  84.         }
  85.         txt_modes++;
  86.         }
  87.         if(gtab[gra_modes].width != 0) {
  88.         unsigned int numc = gtab[gra_modes].number_of_colors;
  89.         if(vdr_driver) {
  90.             mode  = gtab[gra_modes].mode.vdr.BIOS_mode;
  91.             setup = gtab[gra_modes].mode.vdr.custom_setup_index;
  92.         }
  93.         else {
  94.             mode  = gtab[gra_modes].mode.grn.BIOS_mode;
  95.             setup = gtab[gra_modes].mode.grn.custom_setup_index;
  96.         }
  97.         sprintf(gentry,
  98.             "(g%d%s  %4dx%-4d C:%-8lu %s",
  99.             gra_modes+1,
  100.             ((gra_modes < 9) ? ") " : ")"),
  101.             gtab[gra_modes].width,
  102.             gtab[gra_modes].height,
  103.             (numc < 0xc000U) ? (long)numc : (1L << (numc & 0xff)),
  104.             (mode == unsup) ?
  105.             "Disabled" :
  106.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  107.         );
  108.         if((mode != unsup) && (setup != 0)) {
  109.             sprintf(buf," *%d*",setup);
  110.             strcat(gentry,buf);
  111.         }
  112.         gra_modes++;
  113.         }
  114.         printf("%-35s%s\n",tentry,gentry);
  115.     }
  116.     printf("\nEnter mode to test or 'Q' to quit: ");
  117.     fflush(stdout);
  118. }
  119.  
  120. void test_textmode(int mode)
  121. {
  122.     int ii;
  123.  
  124.     if(mode < 0) return;
  125.     if(mode >= txt_modes) return;
  126.     if(ttab[mode].mode.grn.BIOS_mode == 0xff) return;
  127.     GrSetMode(GR_width_height_text,ttab[mode].width,ttab[mode].height);
  128.     do {
  129.         printf("\n\nThis is a text mode of width=%d by height=%d\n",
  130.         ttab[mode].width,
  131.         ttab[mode].height
  132.         );
  133.         for(ii = 4; ii < 512; ii += 4) printf("%4d",ii);
  134.         printf("\nPress any key to abort this test...");
  135.         fflush(stdout);
  136. #ifdef __TURBOC__
  137.         delay(2000);
  138. #endif
  139. #ifdef __GNUC__
  140.         sleep(2);
  141. #endif
  142.     } while(!kbhit());
  143.     getkey();
  144. }
  145.  
  146. #define XP(x)    (int)((((long)(x) * (long)xsize) / 100L) + xpos)
  147. #define YP(y)    (int)((((long)(y) * (long)ysize) / 100L) + ypos)
  148.  
  149. void drawing(int xpos,int ypos,int xsize,int ysize,int fg,int bg)
  150. {
  151.     int ii;
  152.  
  153.     if(bg != GrNOCOLOR) {
  154.         GrFilledBox(xpos,ypos,xpos+xsize-1,ypos+ysize-1,bg);
  155.     }
  156.     GrLine(XP(10),YP(10),XP(40),YP(40),fg);
  157.     GrLine(XP(40),YP(10),XP(10),YP(40),fg);
  158.     GrLine(XP(35),YP(10),XP(65),YP(40),fg);
  159.     GrLine(XP(35),YP(40),XP(65),YP(10),fg);
  160.     GrLine(XP(70),YP(10),XP(90),YP(40),fg);
  161.     GrLine(XP(70),YP(40),XP(90),YP(10),fg);
  162.     for(ii = 0; ii < 5; ii++) {
  163.         GrBox(XP(70+2*ii),YP(10+3*ii),XP(90-2*ii),YP(40-3*ii),fg);
  164.     }
  165.     GrFilledBox(XP(10),YP(50),XP(60),YP(90),fg);
  166.     GrBox(XP(70),YP(50),XP(90),YP(90),fg);
  167.     for(ii = 0; ii < 100; ii++) {
  168.         GrPlot(XP((random() % 20) + 70),YP((random() % 40) + 50),fg);
  169.     }
  170. }
  171.  
  172. void test_graphicsmode(int mode)
  173. {
  174.     char buf[100];
  175.  
  176.     if(mode < 0) return;
  177.     if(mode >= gra_modes) return;
  178.     if(gtab[mode].mode.grn.BIOS_mode == 0xff) return;
  179.     GrSetMode(GR_width_height_color_graphics,
  180.         gtab[mode].width,
  181.         gtab[mode].height,
  182.         gtab[mode].number_of_colors
  183.     );
  184.     sprintf(buf,
  185.         "%dx%d graphics with %d colors",
  186.         GrSizeX(),
  187.         GrSizeY(),
  188.         GrNumColors()
  189.     );
  190.     GrClearScreen(GrBlack());
  191.     drawing(0,0,GrSizeX(),GrSizeY()-35,GrWhite(),GrNOCOLOR);
  192.     GrTextXY(0,GrSizeY()-32,buf,GrWhite(),GrNOCOLOR);
  193.     GrTextXY(0,GrSizeY()-16,"Press any key to continue...",GrWhite(),GrNOCOLOR);
  194.     getkey();
  195. }
  196.  
  197. void main(void)
  198. {
  199.     char reply[80];
  200.     long flags;
  201.  
  202.     GrSetMode(GR_default_text);
  203.     flags = _GrGetDriverModes(&ttab,>ab);
  204.     if(!ttab || !gtab) {
  205.         printf("MODETEST will work only with a new format driver\n");
  206.         exit(0);
  207.     }
  208.     if((flags & 0xffff0000L) == GR_DRV_VER_VDR) {
  209.         vdr_driver = 1;
  210.         unsup = 0xfff;
  211.     }
  212.     for( ; ; ) {
  213.         GrSetMode(GR_default_text);
  214.         list_modes();
  215.         gets(reply);
  216.         switch(tolower(reply[0])) {
  217.           case 't':
  218.         test_textmode(atoi(&reply[1]) - 1);
  219.         break;
  220.           case 'g':
  221.         test_graphicsmode(atoi(&reply[1]) - 1);
  222.         break;
  223.           case 'q':
  224.         GrSetMode(GR_default_text);
  225.         exit(0);
  226.         }
  227.     }
  228. }
  229.  
  230.